﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace StoreWeb.ajax
{
    public partial class dictionarytype : System.Web.UI.Page
    {
        Maticsoft.BLL.DictionaryType bll = new Maticsoft.BLL.DictionaryType();
        Maticsoft.BLL.Dictionary dbll = new Maticsoft.BLL.Dictionary();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int row = 0;
                if (!string.IsNullOrEmpty(Request["action"]) && Request["action"] == "delete")
                {
                    if (dbll.GetModelList("typeid="+Request["id"]).Count > 0)
                        Response.Write("3");
                    else
                        Response.Write((bll.Delete(Convert.ToInt32(Request["id"])) ? "1" : "0"));
                }
                else
                {
                    Maticsoft.Model.DictionaryType md = new Maticsoft.Model.DictionaryType();
                    if (!string.IsNullOrEmpty(Request["id"]))
                    {
                        md = bll.GetModel(Convert.ToInt32(Request["id"]));
                        md.note = Request["note"];
                        md.typename = Request["name"];
                        row = bll.Update(md) ? 2 : 0;
                    }
                    else
                    {
                        md.createtime = DateTime.Now;
                        md.note = Request["note"];
                        md.typename = Request["name"];
                        md.isdel = 0;
                        row = bll.Add(md) > 0 ? 1 : 0;
                    }
                    if (row == 1)
                    {
                        Response.Write("1");
                    }
                    else if (row == 2)
                    {
                        Response.Write("2");
                    }
                    else
                    {
                        Response.Write("0");
                    }
                }
            }
        }
    }
}